package gw.com.android.ui.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import gw.com.android.app.ActivityManager;
import gw.com.android.app.AppMain;
import gw.com.android.app.GTConfig;
import gw.com.android.model.ConfigType;
import www.com.library.util.DeviceUtil;

/**
 * 游客登录时提示弹层
 * @author Administrator
 *
 */
public class LoginDialog extends BaseDialog implements OnClickListener {

	public LoginDialog(Context context, String content) {
		super(context);
		mContent = content;
	}

	private TextView mView;
	private String mContent = "";
	/**
	 * 显示弹层
	 * @param act
	 */
	public static void showLoginDialog(Activity act, String content){
		mInstance = new LoginDialog(act,content);
		mInstance.show();
	}
	/**
	 * 显示弹层
	 * @param act
	 * @param content
	 * @param canceleable 设置点击边缘是否可以消失
	 */
	public static void showLoginDialog(Activity act, String content,boolean canceleable){
		mInstance = new LoginDialog(act,content);
		mInstance.setCanceledOnTouchOutside(canceleable);
		mInstance.show();
		
	}
	
	@Override
	public void initParam() {
		mCustomViewResId = R.layout.dialog_tourist_login_content;
		mBtnPosText = AppMain.getAppString(R.string.btn_login);
		mBtnNegText = AppMain.getAppString(R.string.btn_add_account);
		int padding = (int) (15 * DeviceUtil.instance().getScreenDensity(mOwnerAct));
		setPadding(padding, 0, padding, 0);
	}

	@Override
	public void inflaterCustomView(View mCustomView) {
		mView = (TextView) mCustomView.findViewById(R.id.dialog_content_text);
		mBtnPos.setOnClickListener(this);
		mBtnNeg.setOnClickListener(this);
		if(mContent.length() > 0){
			mView.setText(mContent);
		}
	}

	// -------------------------------------------------------------
	// Functions of OnClickListener
	// -------------------------------------------------------------
	@Override
	public void onClick(View v) {
		v.setClickable(false);
		v.setEnabled(false);
		dismiss();
		switch (v.getId()) {
		// 登录
		case R.id.action_btn_pos:
			GTConfig.instance().setAccountType(GTConfig.ACC_TYPE_REAL);
			ActivityManager.backLogin(mOwnerAct, false);
			break;
			// 开户
        case R.id.action_btn_neg:
			ActivityManager.showOpenAccount(mOwnerAct, ConfigType.ADD_LOGIN_REAL_TAG);
			break;
		}
	}
}
